export const storage = new Proxy(localStorage, {
  get(target, key) {
    switch (key) {
      case 'getItem':
        return (key) => target.getItem(key);

      case 'setItem':
        return (key, value) => {
          window.events.emit('set-item', { key, value });
          target.setItem(key, value);
        };

      case 'clear':
        return target.clear();

      case 'removeItem':
        return (key) => {
          window.events.emit('remove-item', key);
          target.removeItem(key);
        };
      case 'length':
        return target.length;
      case 'key':
        return (index) => target.key(index);

      default:
        break;
    }
  },
});
